﻿using System.Transactions;
using Abp.Dependency;
using Abp.Domain.Uow;
using Abp.EntityFrameworkCore;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Abp.EntityFrameworkCore.Uow;

namespace AbpDemo.EntityFrameworkCore
{
    [DependsOn(
        typeof(AbpDemoCoreModule), 
        typeof(AbpEntityFrameworkCoreModule))]
    public class AbpDemoEntityFrameworkCoreModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(AbpDemoEntityFrameworkCoreModule).GetAssembly());
        }

        
        public override void PostInitialize()
        {
            //TODO:Goods seed
            using (var uowManager = IocManager.ResolveAsDisposable<IUnitOfWorkManager>())
            {
                using (var uow = uowManager.Object.Begin(TransactionScopeOption.Suppress))
                {
                    var context = uowManager.Object.Current.GetDbContext<AbpDemoDbContext>();
                    context.GoodsSeed();
                    uow.Complete();
                }
            }
        }
    }
}